import { createApp, ref, toRef } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'

import { globalRegisterComp } from './utils/globalRegisterComponent'
import {globalKey} from '@/utils/symbolKeys'
import {globalDirective} from '@/directive/index'
import i18n from '@/plugins/i18n'
import { useDemoStore } from './stores/demo'
// import './assets/main.css'

// vue 实例
const app = createApp(App)
// 使用 插件 必须在挂载前
const pinia = createPinia()

// pinia.use((context)=>{
//   console.log("context===>",context);
//   const {app,options,store,pinia} = context

//   // 
//   return {
//     secret:'我的秘密'
//   }
// })

pinia.use(({store})=>{
  store.hello = ref('world')
  if (process.env.NODE_ENV === 'development') {
    // 添加你在 store 中设置的键值
    store._customProperties.add('hello')
  }

  if (!Object.prototype.hasOwnProperty(store.$state, 'hasError')) {
    const hasError = ref(false)
    store.$state.hasError = hasError
  }
  store.hasError = toRef(store.$state, 'hasError')
})



app.use(pinia)

app.use(router)
// app.use(i18n,{
//   home:{
//     title:'标题'
//   }
// })
// 全局注册组件
globalRegisterComp(app)
// 全局提供依赖
app.provide(globalKey,{name:'zs',age:18})
// app.provide('msg',[1,2,3])


// 全局注册指令
// app.directive('focus',(el,binding)=>{
//   el.focus()
// })

globalDirective(app)

// 挂载 mount()
app.mount('#app')


